package com.qf.homework.controller;

import cn.hutool.jwt.JWT;

import com.qf.homework.service.TicketService;
import com.qf.homework.vo.ResultVo;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.UnsupportedEncodingException;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/ticket")
public class Controller {

    @Resource
    TicketService ticketService;

    //返回的Vo中code为0 代表获取新token成功  为-1 代表获取新token失败  前端进行提示
    @GetMapping("/get-token")
    public ResultVo add(String phone)   {
        return ticketService.getToken(phone);
    }
    @GetMapping("/vote")
    public ResultVo vote(String starName, String phone, HttpServletRequest request){

        String token1 = request.getHeader("token");
        return ticketService.vote(starName,phone, token1);
    }
    @GetMapping("/get-ticket")
    public ResultVo getTicket(){
        return ResultVo.success(ticketService.list());
    }

}
